<%@ page language="java" contentType="text/html; charset=utf-8"
	import="java.util.*,kk.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
    <title>My JSP 'topicadd.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <%	
  		String name=request.getParameter("tname");
  		if(name.equals(""))
  		out.println("<script>alert('主题不能为空！');location.replace('admin.jsp');</script>");
		TopicDao tdao=new TopicDao();
		List<Topic> l=tdao.findAll();
		for(Topic t:l){
    		if(t.getTname().equals(name))
    			out.println("<script>alert('与现有主题重名,增加失败！系统返回');history.back();</script>");
    }
    Topic t=new Topic();
    t.setTname(name);
    int i=tdao.add1(t);
    if(i>0)
    	out.println("<script>alert('增加主题成功！');location.replace('admin.jsp');</script>");
    else
    	out.println("<script>alert('增加主题失败！系统返回！');history.back();</script>");
    %>
  </body>
</html>
